package com.ce.thd;

import java.util.List;

import com.ce.po.VFilmDO;
import com.ce.po.VSeriesDO;
import com.ce.po.VTagDO;
import com.ce.po.VTypeDO;
import com.ce.utils.EtvNetWork;
import com.ce.utils.FileOperate;
import com.ce.utils.NWTransform;

public class WriteRunnable implements Runnable {
	private String[] channels = null;
	
	public WriteRunnable(String[] channels) {
		this.channels = channels;
	}

	public void run() {
		try {
			for (int j = 0; j < channels.length; j++) {
				FileOperate fileOperate = new FileOperate("E:\\wypsmall\\Code\\Code_j2ee_e34\\NewEtvSDExport\\exp.properties");
				fileOperate.prepare();
				String channel = channels[j];
				Thread.sleep(500);
				String tagsJson = EtvNetWork.getTags(channel);
				fileOperate.writeTagProperties(tagsJson, channel);
				List<VTagDO> tags = NWTransform.transformJsonToTags(tagsJson);
				for (VTagDO tagDO : tags) {
					System.out.println(tagDO);
					for (VTypeDO typeDO : tagDO.getTypes()) {
						for (int i = 1; i <= 1; i++) {
							String page = ""+i;
							String type = typeDO.getId();
							Thread.sleep(500);
							String listJson = EtvNetWork.getList(channel, type, page);
							fileOperate.writeListProperties(listJson, channel, type, page);
							List<VFilmDO> films = NWTransform.transformJsonToList(listJson);
							for (VFilmDO filmDO : films) {
								Thread.sleep(500);
								String detailJson = EtvNetWork.getDetail(filmDO.getId(), filmDO.getType());
								fileOperate.writeDetailProperties(detailJson, filmDO.getId(), filmDO.getType());
								VSeriesDO seriesDO = NWTransform.transformJsonToVSeriesDO(detailJson);
								//System.out.println(seriesDO.getSets().get(0).getSource());
							}
							fileOperate.flush();
						}
						fileOperate.flush();
					}
				}
				fileOperate.finish();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
